package com.nineclock.attendance.controller;

import com.nineclock.attendance.AttendPunchControllerApi;
import com.nineclock.attendance.dto.AttendPunchDTO;
import com.nineclock.attendance.dto.AttendPunchUserWholeDayDTO;
import com.nineclock.attendance.pojo.AttendPunch;
import com.nineclock.attendance.service.AttendPunchService;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping
public class AttendPunchController implements AttendPunchControllerApi {
	
    @Autowired
    private AttendPunchService attendPunchService;
	
    //打卡
    @Override
    @PostMapping("/punch")
    public Result punch(@RequestBody AttendPunchDTO attendPunchDTO) {
        attendPunchService.punch(attendPunchDTO);
        return Result.success();
    }

    /**
     * 根据id获取全天打卡信息
     * @return
     */
    //获取打卡记录
    @Override
    @GetMapping("/get")
    public Result<AttendPunchUserWholeDayDTO> queryPunchRecord() {
        AttendPunchUserWholeDayDTO attendPunchUserWholeDayDTO = attendPunchService.queryPunchRecord();
        return Result.success(attendPunchUserWholeDayDTO);
    }

    /**
     * 查询指定时间段内的考勤列表数据
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    @GetMapping("/members")
    public Result<List<AttendPunchDTO>> queryMembers(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime) {
        List<AttendPunchDTO> attendPunchDTOList = attendPunchService.queryMembers(startTime, endTime);
        return Result.success(attendPunchDTOList);

    }

    /**
     * 导出指定时间段之内的考勤数据
     * @param startTime
     * @param endTime
     * @throws IOException
     */
    @Override
    @GetMapping("/export")
    public void exportAttendData(String startTime, String endTime) throws IOException {
        attendPunchService.exportAttendData(startTime, endTime);
    }
}    